<?php

/**
 * Autenticacion actions.
 *
 * @package    fiei
 * @subpackage Autenticacion
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class AutenticacionActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeLogin(sfWebRequest $request)
  {
    $this->form = new loginForm();
    
    if($request->isMethod('post'))
    {
      $this->form->bind($request->getParameter('user_login'));
      if($this->form->isValid())
      {
      	$usuario = Doctrine::getTable('Usuario')->findOneByLogin($this->form->getValue('login'));
      	$this->getUser()->logIn($usuario);
      	$this->redirect('@inicio');
      }
    }
  }
  
  public function executeLogout()
  {
  	if($this->getUser()->estaAutenticado())
  	{
  	  $this->getUser()->setAuthenticated(false);
  	}
  	
  	return $this->redirect('@login');
  }
}